package com.common.utils;

import java.math.BigDecimal;

/**
 * Created by Administrator on 2015/7/29.
 */
public class NumberUtil {
    public static int compare(Number n1, Number n2){
        BigDecimal b1 = null;
        BigDecimal b2 = null;
        if (n1 instanceof BigDecimal){
            b1 = (BigDecimal) n1;
        }else if(n1 != null){
            b1 = new BigDecimal(n1.doubleValue());
        }
        if (n2 instanceof BigDecimal){
            b2 = (BigDecimal) n2;
        }else if (n2 != null){
            b2 = new BigDecimal(n2.doubleValue());
        }

        if (b1 == null && b2 == null){
            return 0;
        }
        if (b1 == null && b2 != null){
            return -1;
        }
        if (b1 != null && b2 == null){
            return 1;
        }
        return b1.compareTo(b2);
    }
}
